package com.ruoyi.web.controller.hr;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.hr.domain.BizLeavetime;
import com.ruoyi.hr.service.IBizLeavetimeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 【请假申请】Controller
 * 
 * @author ruoyi
 * @date 2025-03-18
 */
@RestController
@RequestMapping("/hr/leavetime")
public class BizLeavetimeController extends BaseController
{
    @Autowired
    private IBizLeavetimeService bizLeavetimeService;

    /**
     * 查询【请假申请】列表
     */
    @PreAuthorize("@ss.hasPermi('system:leavetime:list')")
    @GetMapping("/list")
    public TableDataInfo list(BizLeavetime bizLeavetime)
    {
        startPage();
        List<BizLeavetime> list = bizLeavetimeService.selectBizLeavetimeList(bizLeavetime);
        return getDataTable(list);
    }

    /**
     * 导出【请假申请】列表
     */
    @PreAuthorize("@ss.hasPermi('system:leavetime:export')")
    @Log(title = "【请假申请】", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BizLeavetime bizLeavetime)
    {
        List<BizLeavetime> list = bizLeavetimeService.selectBizLeavetimeList(bizLeavetime);
        ExcelUtil<BizLeavetime> util = new ExcelUtil<BizLeavetime>(BizLeavetime.class);
        util.exportExcel(response, list, "【请假申请】数据");
    }

    /**
     * 获取【请假申请】详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:leavetime:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(bizLeavetimeService.selectBizLeavetimeById(id));
    }

    /**
     * 新增【请假申请】
     */
    @PreAuthorize("@ss.hasPermi('system:leavetime:add')")
    @Log(title = "【请假申请】", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BizLeavetime bizLeavetime)
    {
        bizLeavetime.setUserId(getUserId());
        bizLeavetime.setUserName(getUsername());
        return toAjax(bizLeavetimeService.insertBizLeavetime(bizLeavetime));
    }

    /**
     * 修改【请假申请】
     */
    @PreAuthorize("@ss.hasPermi('system:leavetime:edit')")
    @Log(title = "【请假申请】", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BizLeavetime bizLeavetime)
    {
        return toAjax(bizLeavetimeService.updateBizLeavetime(bizLeavetime));
    }

    /**
     * 删除【请假申请】
     */
    @PreAuthorize("@ss.hasPermi('system:leavetime:remove')")
    @Log(title = "【请假申请】", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(bizLeavetimeService.deleteBizLeavetimeByIds(ids));
    }
}
